package com.azdebugit.java8.suanfa.mingan;

import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

/**
 * @date 2021/9/30 10:10
 * <p>
 * 加载jar包内的违禁词文件加载器
 */
@SuppressWarnings("unused")
public class SensitiveWordJarFileLoader extends SensitiveWordAbstractFileLoader {

    public SensitiveWordJarFileLoader(String relativePath, String separator) {
        super(relativePath, StandardCharsets.UTF_8, separator);
    }

    public SensitiveWordJarFileLoader(String relativePath) {
        super(relativePath, StandardCharsets.UTF_8, ",");
    }

    /**
     * 构造器
     *
     * @param relativePath 相对路径,包含文件名(位于resources目录下)
     * @param charset      字符集
     * @param separator    分隔符
     */
    public SensitiveWordJarFileLoader(String relativePath, Charset charset, String separator) {
        super(relativePath, charset, separator);
    }

    @Override
    public void initInputStream() {
        try {
            ClassPathResource classPathResource = new ClassPathResource(filePath);
            inputStream = classPathResource.getInputStream();
        } catch (IOException e) {
            throw new IllegalStateException("load sensitive word file in jar failed,message = " + e.getMessage());
        }
    }
}